package com.example.mr5.mygame.main;/**
 * Created by Mr.5
 * Date：2016/5/15.
 * Time：15:44
 */

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mr5.mygame.R;
import com.example.mr5.mygame.modle.Game;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mr.5 
 * Date：2016/5/15.
 * Time：15:44
 */
public class HomeGridViewAdapter extends BaseAdapter {
    private List<Game> gameList = new ArrayList<Game>();
    private Context context;

    public HomeGridViewAdapter(Context context,List<Game> list){
        this.context = context;
        this.gameList = list;
    }

    @Override
    public int getCount() {
        return gameList.size();
    }

    @Override
    public Object getItem(int position) {
        return gameList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(null == convertView){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_home_gridview, null);
        }
        ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
        TextView title = (TextView) convertView.findViewById(R.id.title);
        TextView summary = (TextView) convertView.findViewById(R.id.summary);


        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), gameList.get(position).getIcon());
        icon.setImageBitmap(bmp);

        title.setText(gameList.get(position).getName());
        summary.setText(gameList.get(position).getSummary());

        return convertView;
    }
}
